<?php

/**
 * @Author: vannvan
 * @Date:   2018-12-02 22:08:31
 * @Last Modified by:   vannvan
 * @Last Modified time: 2018-12-02 23:54:31
 */
error_reporting(E_ALL^E_NOTICE); //关闭notice级别的提示
header("Content-type: text/html; charset=utf-8");
$content=strval($_POST['content']);
if($content==''){
	$arr = array('status' =>0 ,msg=>'没有数据' );
	exit(json_encode($arr,JSON_UNESCAPED_UNICODE));
}
$myfile = fopen("uploadfile/test.md", "w");
$txt = $content;
$rst=fwrite($myfile, $txt);
if($rst){
	$arr = array('status' =>2 ,'msg'=>'创建成功' );
	exit(json_encode($arr,JSON_UNESCAPED_UNICODE));
}else{
	$arr = array('status' =>3 ,'msg'=>'创建失败' );
	exit(json_encode($arr,JSON_UNESCAPED_UNICODE));
}
$con=new mysqli("localhost", "root", "sewen744926", "editor");
if(!$con){
	die("连接失败!".mysql_errno());
}else{
	//echo "连接数据库成功<br/>";
$con->query('set names utf8;'); 
$sql="INSERT INTO article (content) VALUES ('$content')"; 
if($result = $con->query($sql)){
	header('Content-Type:application/json; charset=utf-8');
    $arr = array('status'=>1);
	exit(json_encode($arr,JSON_UNESCAPED_UNICODE));
}else{
	echo "插入失败";
}
}


